
drop proc p280_xxxx
go
create procedure p280_xxxx
/*
  -----------------------------------------------------------------------
      P280_XXXX - Insert/Retrieve IAS Users.
  -----------------------------------------------------------------------
*/

/*
    ------  INPUT VARIABLES   ------
*/
   @actn  char(1)  = "R"
 , @user  char(8)  = " " 
 , @name  char(30) = " "
 , @pswd  char(8)  = " " 
 , @badge char(6)  = " " 
as
/*
    ------ INTERNAL VARIABLES ------
*/

/************************************************************************
   Action code 'I' = Insert/Update a user to d280db1.dbo.t280users.
   Action code 'D' = Delete an existing users in d280db1.dbo.t280users.
   Action code 'R' = Report all users from d280db1.dbo.t280users.
 ************************************************************************/

if @actn = 'I'
   goto InsertUser 

if @actn = 'U'
   goto UpdateUser 

if @actn = 'D'
   goto DeleteUser 

if @actn = 'R'
   goto ReportUser 


ReportUser:

/************************************************************************
   Get all User Users and System Users 
 ************************************************************************/

begin
   select a_uid_c          
        , a_uid_x        
        , a_badge_n      
     from d280db1.dbo.t280users
    order by a_uid_c 
end
  goto ENDIT 

UpdateUser:

/************************************************************************
   Update User Info 
 ************************************************************************/

begin
   update d280db1.dbo.t280users
      set a_uid_x   = @name         
        , a_badge_n = @badge
        , db_upd_d  = getdate()
    where a_uid_c   = @user
end
  goto ReportUser


InsertUser:

/************************************************************************
   Insert a new User
 ************************************************************************/

begin
   delete from d280db1.dbo.t280users
    where a_uid_c  = @user

   insert into d280db1.dbo.t280users
    ( a_uid_c         
    , a_uid_x         
    , a_pswd_c       
    , a_badge_n
    , db_upd_d )
   values
    ( @user 
    , @name 
    , @pswd
    , @badge
    , getdate())
end
  goto ReportUser


DeleteUser:

/************************************************************************
   Delete an existing User
 ************************************************************************/

begin
   delete from d280db1.dbo.t280users
    where a_uid_c  = @user
end
  goto ReportUser


ENDIT: 

/************************************************************************
   Return to the calling environment
 ************************************************************************/

return ( 0 )
go
